/*
 * Copyright (c) 2010 Philip Foulkes <philip.foulkes@gmail.com>
 *
 * This file is free software and is made available under the 
 * terms of the GNU General Public License, version 2, or at your
 * option, any later version
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef _MRP_ATTRIBUTE_H_
#define _MRP_ATTRIBUTE_H_

#define MRP_ATTRIBUTE_VALUE_MIN	1
#define MRP_ATTRIBUTE_VALUE_MAX	255

struct mrp_attribute
{
	struct list_head list;
	
	int attribute_type; /* value 0 is reserved, and shall not be used as an AttributeType by any MRP application. MRP applications may otherwise allocate meanings to any set of values of AttributeType in the range 1 through 255. */
	void * attribute_value; 
	int attribute_value_length;
	int four_packed_type;
	mrp_attribute_value_compare mrp_attribute_value_compare;
	
	struct mrp * mrp;
	
	struct mrp_applicant * mrp_applicant;
	struct mrp_registrar * mrp_registrar;
};

struct mrp_attribute * mrp_attribute_create_and_init (struct mrp * mrp, int attribute_type, void * attribute_value, int attribute_value_length, int four_packed_type, mrp_attribute_value_compare mrp_attribute_value_compare);
void mrp_attribute_destroy (struct mrp_attribute ** mrp_attribute);

int mrp_attribute_get_attribute_type (struct mrp_attribute * mrp_attribute);
void * mrp_attribute_get_attribute_value (struct mrp_attribute * mrp_attribute);
int mrp_attribute_set_attribute_value (struct mrp_attribute * mrp_attribute, void * attribute_value, int attribute_value_length);
int mrp_attribute_get_attribute_value_length (struct mrp_attribute * mrp_attribute);
int mrp_attribute_get_four_packed_type (struct mrp_attribute * mrp_attribute);

int mrp_attribute_is_registered (struct mrp_attribute * mrp_attribute);
int mrp_attribute_is_leaving (struct mrp_attribute * mrp_attribute);
int mrp_attribute_is_empty (struct mrp_attribute * mrp_attribute);

int mrp_attribute_compare (struct mrp_attribute * mrp_attribute, int attribute_type, void * attribute_value);

int mrp_attribute_perform_new (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_join (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_lv (struct mrp_attribute * mrp_attribute);

int mrp_attribute_perform_periodic_protocol_action (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_new (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_join_in (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_in (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_join_mt (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_mt (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_lv (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_la (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_tx_la (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_receive_leave_all (struct mrp_attribute * mrp_attribute);

int mrp_attribute_perform_mad_join_indication (struct mrp_attribute * mrp_attribute, int new);
int mrp_attribute_perform_mad_leave_indication (struct mrp_attribute * mrp_attribute);

int mrp_attribute_perform_send_join (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_send_new (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_send_leave (struct mrp_attribute * mrp_attribute);
int mrp_attribute_perform_send (struct mrp_attribute * mrp_attribute);

int mrp_attribute_request_transmit_opportunity (struct mrp_attribute * mrp_attribute, struct mrp_applicant * mrp_applicant);

int mrp_attribute_registrar_leave_timer_expire_notify (struct mrp_attribute * mrp_attribute);

#endif
